/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Grid = require("grid");
	var Dialog = require("dialog");
	var store = require("store");
	var Form = require("form");
	
    var instance = {
        initComponent: function (params, widget) {
        	var checkMeetingDetailGrid = new Grid({
        	    parentNode: "#checkInMeeting",
        	    autoRender: false,
        	    model: {
        	    	head : {
						buttons : [ {
							//parentNode:'.J-demo',
							id : "addMeeting",
//							type : "button",
							text : "新增",
							handler: function () {
						        var meetForm = new Form({
						          parentNode:".J-form",
						          show:false,
						          autoRender: false,
						          model: {
									 layout: "2_1",
						             defaultButton: false,
						              items: [{
					        				 name:"pkCheckInMeeting",
					 						 type:"hidden"
					        			},{
					        				name:"version",
											type:"hidden",
											defaultValue:"0"
					        			},{
					        				name:"meetingDate",
					        				label:"会议时间",
					        				type: "date",
					        				mode:"YYYY-MM-DD HH:mm",
					        				validate:["required"]
					        			},{
					        				name:"screenings",
					        				label:"场次"
					        			},{
					        				name:"meetingRoom",
					        				label:"会议室",
					        				validate:["required"]
					        			},{
					        				name:"peoCount",
					        				label:"参会人数",
					        				validate:["required"]
					        			},{
					        				name:"meetPlaceType",
					        				label:"会议台型"
					        			},{
					        				name:"content",
					        				label:"例牌横幅",
					        				"break": true
					        			},{
					        				name:"contentLED",
					        				label:"前厅LED",
					        				"break": true
					        			},{
					        				name:"license",
					        				label:"水牌",
					        				"break": true
					        			},{
					        				name:"description",
					        				label:"备注",
					        				"break": true,
					        				type: "textarea"
					        			}]
						          }
						    	});
						        widget.set("meetForm",meetForm);
						        Dialog.showComponent(meetForm, {
    								defaultButton:false,
    								title: "添加会议",
    								buttons :[{
    									id:"save",
    									text:"确定",
     									className:"btn-primary",
    									handler:function(){
    										var formData=widget.get("meetForm").getData();
    										var flag =	widget.get("meetForm").get("flag");
    										/*if(!formData.meetingDate){
    											Dialog.alert({
    												content: "会议准备--请填写会议日期！"
    											});
    											return false;
    										}
    										if(!formData.screenings){
    											Dialog.alert({
    												content: "会议准备--请填写场次！"
    											});
    											return false;
    										}
    										if(!formData.peoCount){
    											Dialog.alert({
    												content: "会议准备--请填写参会人数！"
    											});
    											return false;
    										}*/
    										var cParams={
    												haveMeeting:true,
    												meetingDate:formData.meetingDate,
    												meetingRoom:formData.meetingRoom,
    												peoCount:formData.peoCount,
    												pkCheckInMeeting:formData.pkCheckInMeeting,
    												haveMeeting:formData.haveMeeting,
    												meetPlaceType:formData.meetPlaceType,
    												content:formData.content,
    												contentLED:formData.contentLED,
    												license:formData.license,
    												description:formData.description,
    												version:formData.version,
    												screenings:formData.screenings,
    										};
    										var meetGrid = widget.get("checkMeetingDetailGrid");
    										var gridData = meetGrid.getData();
    										if(flag!=null){
    											gridData[flag] = cParams;
    										}else{
    											gridData.push(cParams);
    										}
    										meetGrid.setData(gridData);
    										Dialog.close();
    									}
    								},{
    									id:"close",
    									text:"取消",
    									handler:function(){
    										Dialog.close();
    									}
    								}]
    							});
						        //addgrid.refresh();
						      }
						}]
					},
        	        columns: [/*{
        	            name: "haveMeeting",
        	            label: "是否会议"
        	        },*/ {
        	            name: "meetingDate",
        	            label: "会议时间",
        	            format: "date",
        	            formatparams: {
        	                mode: "YYYY-MM-DD HH:mm:SS"
        	            }
        	        }, {
        	            name: "meetingRoom",
        	            label: "会议室"
        	        }, {
        	            name: "peoCount",
        	            label: "参会人数",
        	        }, {
        	        	name:"screenings",
        	        	label:"场次"
        	        }, {
        	            name: "description",
        	            label: "操作",
        	            format:"button",
        	            formatparams:[{
        					id:"delete",
        					text:"删除",
        					show:function(value,data){
        						if(data.status){
        							if(data.status.key == "Initial" || data.status.key == "Edited"||data.status.key == "Pending"){
        								return true;
        							}else{
        								return false;
        							}
        						}else{
        							return true;
        						}
        					},
        					handler:function(index,data,rowEle){
        						var meetGrid = widget.get("checkMeetingDetailGrid");
        						var gridData = meetGrid.getData();
        						gridData.splice(index,1);
        						meetGrid.setData(gridData);
        					}
        				
        	            },{
        	            	id:"edit",
        	            	text:"修改",
        	            	show:function(value,data){
        						if(data.status){
        							if(data.status.key == "Initial" || data.status.key == "Edited"||data.status.key == "Pending"){
        								return true;
        							}else{
        								return false;
        							}
        						}else{
        							return true;
        						}
        					},
        					handler:function(index,data,rowEle){
        						$(".actions").eq(6).children().click();
        						widget.get("meetForm").setData(data);
        						widget.get("meetForm").set("flag",index);
        					}
        	            }]
        	        }]
        	    }
        	});
        	widget.set("checkMeetingDetailGrid",checkMeetingDetailGrid);
        }
    };
    module.exports = instance;
});
